home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
debugnub
/
RDTProcs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-17
|
19KB
|
730 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/*
* RDTProcs.c
*
* Stubs for remote debug tool.
*
* Demers, February 20, 1990 9:19:13 am PST
*/
#include "xr/BasicTypes.h"
#include "xr/Errno.h"
#include "xr/CirioNubTypes.h"
#include "xr/CirioNubProtocol.h"
#include "xr/CirioNubProcs.h"
#include "xr/RDTRuntime.h"
#include "xr/RDTProcs.h"
#if (( RDT_PROCS_VERSION ) != ( CIRIO_NUB_PROCS_VERSION ))
--> RDT_PROCS_VERSION != CIRIO_NUB_PROCS_VERSION <--
#endif
static char *
RDT_CopyStr(str)
char *str;
{
char *newStr = NIL;
if( str != NIL ) {
int len1 = 1 + strlen(str);
newStr = (char *)malloc(len1);
bcopy(str, newStr, len1);
}
return newStr;
}
#define RDT_FREE(p) if(((char *)(p)) != NIL) { free( ((char *)(p)) ); }
int
RDT_Null(desiredVersion, resultVersionPtr)
unsigned desiredVersion;
unsigned *resultVersionPtr;
{
CirioNubRetCode rc;
unsigned argc;
unsigned buf[64];
desiredVersion &= 0xffff; /* procs version only */
rc = RDT_PutCard32(
CIRIO_NUB_VERSION(CIRIO_NUB_PROTOCOL_VERSION, desiredVersion) );
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_Null);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 1 ) {
(*resultVersionPtr) =
((unsigned)(buf[0])) & 0xffff; /* procs version only */
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? 0 : (-1) );
}
int
RDT_WaitSig(timeoutMsec, dbStatP)
unsigned timeoutMsec;
int *dbStatP;
{
CirioNubRetCode rc;
bool gotSig;
unsigned argc;
unsigned buf[64];
rc = RDT_PutCard32(timeoutMsec);
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_WaitSig);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 2 ) {
gotSig = ((bool)(buf[0]));
(*dbStatP) = ((int)(buf[1]));
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? (gotSig ? 0 : 1) : (-1) );
}
int /* -err */
RDT_SetDBStat (dbStat, timeoutMsec)
int dbStat;
unsigned timeoutMsec;
{
CirioNubRetCode rc;
int ans;
unsigned argc;
unsigned buf[64];
rc = RDT_PutInt32(dbStat);
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(timeoutMsec);
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_SetDBStat);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 1 ) {
ans = ((int)(buf[0]));
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? ((ans == 0) ? 0 : 1) : (-1) );
}
static int
RDT_GetBlock(addr, nBytes, clientBuf, getProcID)
unsigned addr;
unsigned nBytes;
char *clientBuf;
unsigned getProcID;
{
CirioNubRetCode rc;
int ans;
unsigned argc;
unsigned buf[2048];
rc = RDT_PutCard32(addr);
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(nBytes);
}
if( rc == cnrc_ok ) switch(getProcID) {
case CirioNubProcID_GetBytes:
case CirioNubProcID_GetWords16:
case CirioNubProcID_GetWords32:
break;
default:
rc = cnrc_protocol;
break;
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(getProcID);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 2 ) {
ans = ((int)(buf[0]));
if( ans > 0 ) {
(void) bcopy( ((char *)(buf[1])), clientBuf, ans );
}
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? ans : (-1) );
}
int /* bytesRead or -err */
RDT_GetBytes(addr, nBytes, clientBuf)
unsigned addr;
unsigned nBytes;
char *clientBuf;
{
return RDT_GetBlock( addr, nBytes, clientBuf,
CirioNubProcID_GetBytes );
}
int /* bytesRead or -err */
RDT_GetWords16(addr, nBytes, clientBuf)
unsigned addr;
unsigned nBytes;
unsigned short *clientBuf;
{
return RDT_GetBlock( addr, nBytes, ((char *)(clientBuf)),
CirioNubProcID_GetWords16 );
}
int /* bytesRead or -err */
RDT_GetWords32(addr, nBytes, clientBuf)
unsigned addr;
unsigned nBytes;
unsigned *clientBuf;
{
return RDT_GetBlock( addr, nBytes, ((char *)(clientBuf)),
CirioNubProcID_GetWords32 );
}
static int /* bytesPut or -err */
RDT_PutBlock(addr, nBytes, clientBuf, putProcID)
unsigned addr;
unsigned nBytes;
char *clientBuf;
unsigned putProcID;
{
CirioNubRetCode rc;
int ans = -1;
unsigned argc;
unsigned buf[64];
rc = RDT_PutCard32(addr);
if( rc == cnrc_ok ) switch(putProcID) {
case CirioNubProcID_PutBytes:
rc = RDT_PutBlock8(clientBuf, nBytes);
break;
case CirioNubProcID_PutWords16:
rc = RDT_PutBlock16(((unsigned short *)(clientBuf)), nBytes);
break;
case CirioNubProcID_PutWords32:
rc = RDT_PutBlock32(((unsigned *)(clientBuf)), nBytes);
break;
default:
rc = cnrc_protocol;
break;
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(putProcID);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc != 1 ) rc = cnrc_badArgs;
}
if( rc == cnrc_ok ) {
if( (ans = ((int)(buf[0]))) == 0 ) ans = nBytes;
}
return ans;
}
int /* bytesPut or -err */
RDT_PutBytes(addr, nBytes, clientBuf)
unsigned addr;
unsigned nBytes;
char *clientBuf;
{
return RDT_PutBlock( addr, nBytes, clientBuf,
CirioNubProcID_PutBytes );
}
int /* bytesPut or -err */
RDT_PutWords16(addr, nBytes, clientBuf)
unsigned addr;
unsigned nBytes;
unsigned short *clientBuf;
{
return RDT_PutBlock( addr, nBytes, ((char *)(clientBuf)),
CirioNubProcID_PutWords16 );
}
int /* bytesPut or -err */
RDT_PutWords32(addr, nBytes, clientBuf)
unsigned addr;
unsigned nBytes;
unsigned *clientBuf;
{
return RDT_PutBlock( addr, nBytes, ((char *)(clientBuf)),
CirioNubProcID_PutWords32 );
}
int /* -err */
RDT_GetThread(index, dataPtr)
int index;
CirioNubThreadData *dataPtr;
{
CirioNubRetCode rc;
int ans;
unsigned argc;
CirioNubThreadData fromData, toData;
unsigned buf[1024];
if( index > 0 ) index = (-index);
rc = RDT_PutInt32(index);
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(0);
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_GetThreads);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 2 ) {
switch( ((unsigned)(buf[0])) ) {
case 0:
ans = 1;
break;
case (sizeof (**dataPtr)):
fromData = ((CirioNubThreadData)(buf[1]));
toData = ( (CirioNubThreadData)
(malloc( sizeof (*fromData) )) );
(void) bcopy( fromData, toData, (sizeof (*fromData)) );
/* no strings to copy */
*dataPtr = toData;
ans = 0;
break;
default:
rc = cnrc_badArgs;
break;
}
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? ans : (-1) );
}
void
RDT_FreeThreadData(dataPtr)
CirioNubThreadData *dataPtr;
{
RDT_FREE(*dataPtr);
*dataPtr = NIL;
}
static CirioNubPCInfo /* NIL on failure */
RDT_CopyPCInfoBuf(buf, argc, pos)
unsigned *buf;
unsigned argc;
unsigned pos;
{
CirioNubPCInfo toInfo;
if( argc < (pos+6) ) return NIL;
toInfo = ( (CirioNubPCInfo)(malloc( sizeof (*toInfo) )) );
toInfo->procName = RDT_CopyStr( ((char *)(buf[pos])) ); pos += 1;
toInfo->procSymID = ((unsigned)(buf[pos])); pos += 1;
toInfo->fileName = RDT_CopyStr( ((char *)(buf[pos])) ); pos += 1;
toInfo->fileSeqNum = ((unsigned)(buf[pos])); pos += 1;
toInfo->guessedEmbeddedFileName = RDT_CopyStr( ((char *)(buf[pos])) );
pos += 1;
toInfo->guessedEmbeddedFileSymID = ((unsigned)(buf[pos]));
return toInfo;
}
int /* -err */
RDT_PCtoInfo (pc, infoPtr)
unsigned pc;
CirioNubPCInfo *infoPtr;
{
CirioNubRetCode rc;
unsigned argc;
CirioNubPCInfo toInfo;
unsigned buf[1024];
rc = RDT_PutCard32(pc);
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_PCtoInfo);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 6 ) {
(*infoPtr) = RDT_CopyPCInfoBuf(buf, argc, 0);
if( (*infoPtr) == NIL ) rc = cnrc_badArgs;
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? 0 : (-1) );
}
void
RDT_FreePCInfo(infoPtr)
CirioNubPCInfo *infoPtr;
{
CirioNubPCInfo info;
if( (info= *infoPtr) != NIL ) {
RDT_FREE(info->procName);
RDT_FREE(info->fileName);
RDT_FREE(info->guessedEmbeddedFileName);
free(info);
}
*infoPtr = NIL;
}
int
RDT_KillWorld()
{
CirioNubRetCode rc;
unsigned argc;
unsigned buf[64];
rc = RDT_SendCall(CirioNubProcID_KillWorld);
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 0 ) {
;
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? 0 : (-1) );
}
int /* -err */
RDT_IssueThreadCommand(threadIndex, setFreeze, freeze, setMsg, msg)
int threadIndex;
bool setFreeze;
bool freeze;
bool setMsg;
int msg;
{
CirioNubRetCode rc;
int ans;
unsigned argc;
unsigned buf[128];
rc = RDT_PutInt32(threadIndex);
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(((int)(setFreeze)));
}
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(((int)(freeze)));
}
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(((int)(setMsg)));
}
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(msg);
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_IssueThreadCommand);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 1 ) {
ans = ((int)(buf[0]));
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? ans : (-1) );
}
int /* 0, 1, -err */
RDT_GetDBStat (timeoutMsec, indexPtr, dbStatPtr)
unsigned timeoutMsec;
int *indexPtr;
int *dbStatPtr;
{
CirioNubRetCode rc;
unsigned argc;
unsigned buf[128];
rc = RDT_PutInt32(*dbStatPtr);
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(*indexPtr);
}
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(timeoutMsec);
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_GetDBStat);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc == 2 ) {
(*dbStatPtr) = ((int)(buf[0]));
(*indexPtr) = ((int)(buf[1]));
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? 0 : (-1) );
}
static CirioNubFileEntry /* NIL on failure */
RDT_CopyFileEntryFromBuf(buf, argc, pos)
unsigned *buf;
unsigned argc;
unsigned pos;
{
CirioNubFileEntry toFileEntry;
if( argc < (pos+22) ) return NIL;
toFileEntry = ((CirioNubFileEntry)(malloc(sizeof (*toFileEntry) )));
toFileEntry->seqNum = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->commitPoint = ((bool)(buf[pos])); pos += 1;
toFileEntry->fileName = RDT_CopyStr( ((char *)(buf[pos])) ); pos += 1;
toFileEntry->fOffset = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->fMagic = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->size = ((size_t)(buf[pos])); pos += 1;
toFileEntry->mTime = ((time_t)(buf[pos])); pos += 1;
toFileEntry->sMagic = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->stamp = ((XR_Pointer)(buf[pos])); pos += 1;
toFileEntry->stampSize = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->readerData = ((XR_Pointer)(buf[pos])); pos += 1;
toFileEntry->readerDataSize = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->patchReloc = ((XR_Pointer)(buf[pos])); pos += 1;
toFileEntry->patchSize = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->textReloc = ((XR_Pointer)(buf[pos])); pos += 1;
toFileEntry->textSize = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->dataReloc = ((XR_Pointer)(buf[pos])); pos += 1;
toFileEntry->dataSize = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->bssReloc = ((XR_Pointer)(buf[pos])); pos += 1;
toFileEntry->bssSize = ((unsigned)(buf[pos])); pos += 1;
toFileEntry->commonReloc = ((XR_Pointer)(buf[pos])); pos += 1;
toFileEntry->commonSize = ((unsigned)(buf[pos])); pos += 1;
return toFileEntry;
}
int /* -err */
RDT_GetFileEntry(seqNum, fileEntryPtr)
unsigned seqNum;
CirioNubFileEntry *fileEntryPtr;
{
CirioNubRetCode rc;
int ans;
CirioNubFileEntry toFileEntry;
unsigned argc;
unsigned buf[1024];
rc = RDT_PutCard32(seqNum);
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_GetFileEntry);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
(*fileEntryPtr) = RDT_CopyFileEntryFromBuf(buf, argc, 0);
if( (*fileEntryPtr) != NIL ) {
;
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? 0 : (-1) );
}
void
RDT_FreeFileEntry(fileEntryPtr)
CirioNubFileEntry *fileEntryPtr;
{
CirioNubFileEntry fe;
if( (fe = *fileEntryPtr) != NIL ) {
RDT_FREE(fe->fileName);
free(fe);
*fileEntryPtr = NIL;
}
}
static CirioNubSymEntry
RDT_CopySymEntryFromBuf(buf, argc, pos)
unsigned *buf;
unsigned argc;
unsigned pos;
{
CirioNubSymEntry toSymEntry;
if( argc < (pos+6) ) return NIL;
toSymEntry = ((CirioNubSymEntry)(malloc(sizeof (*toSymEntry) )));
toSymEntry->symID = ((unsigned)(buf[pos])); pos += 1;
toSymEntry->name = RDT_CopyStr( ((char *)(buf[pos])) ); pos += 1;
toSymEntry->type = ((unsigned)(buf[pos])); pos += 1;
toSymEntry->value = ((unsigned)(buf[pos])); pos += 1;
toSymEntry->size = ((unsigned)(buf[pos])); pos += 1;
toSymEntry->fileSeqNum = ((unsigned)(buf[pos])); pos += 1;
return toSymEntry;
}
int /* -err */
RDT_GetMatchingSymEntryByName( symID, pattern, caseSensitive, wantedTypes,
ignoredClasses, numToSkip, symEntryPtr )
unsigned symID;
char *pattern;
bool caseSensitive;
unsigned wantedTypes;
unsigned ignoredClasses;
int numToSkip;
CirioNubSymEntry *symEntryPtr;
{
CirioNubRetCode rc;
unsigned argc;
unsigned buf[2048];
rc = RDT_PutCard32(symID);
if( rc == cnrc_ok ) {
rc = RDT_PutString(pattern);
}
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(((int)(caseSensitive)));
}
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(wantedTypes);
}
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(ignoredClasses);
}
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(numToSkip);
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_GetMatchingSymEntryByName);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc > 0 ) {
if( ((int)(buf[0])) == 0 ) {
(*symEntryPtr) = RDT_CopySymEntryFromBuf(buf, argc, 0);
if( (*symEntryPtr) != NIL ) {
;
} else {
rc = cnrc_badArgs;
}
} else {
(*symEntryPtr) = NIL;
}
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? 0 : (-1) );
}
int /* -err */
RDT_GetMatchingSymEntryByValue( symID, val, wantedTypes, ignoredClasses,
numToSkip, symEntryPtr )
unsigned symID;
unsigned val;
unsigned wantedTypes;
unsigned ignoredClasses;
int numToSkip;
CirioNubSymEntry *symEntryPtr;
{
CirioNubRetCode rc;
int ans;
CirioNubFileEntry toFileEntry;
unsigned argc;
unsigned buf[2048];
rc = RDT_PutCard32(symID);
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(val);
}
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(wantedTypes);
}
if( rc == cnrc_ok ) {
rc = RDT_PutCard32(ignoredClasses);
}
if( rc == cnrc_ok ) {
rc = RDT_PutInt32(numToSkip);
}
if( rc == cnrc_ok ) {
rc = RDT_SendCall(CirioNubProcID_GetMatchingSymEntryByValue);
}
if( rc == cnrc_ok ) {
rc = RDT_ReadReply( buf, (sizeof buf), &argc );
}
if( rc == cnrc_ok ) {
if( argc > 0 ) {
if( ((int)(buf[0])) == 0 ) {
(*symEntryPtr) = RDT_CopySymEntryFromBuf(buf, argc, 0);
if( (*symEntryPtr) != NIL ) {
;
} else {
rc = cnrc_badArgs;
}
} else {
(*symEntryPtr) = NIL;
}
} else {
rc = cnrc_badArgs;
}
}
return ( (rc == cnrc_ok) ? 0 : (-1) );
}